home *** CD-ROM | disk | FTP | other *** search
- unit Runinfo;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, Grids, Menus, StdCtrls, Buttons;
-
- type
- TRunInfoForm = class(TForm)
- Memo1: TMemo;
- ScrollBox1: TScrollBox;
- StringGrid: TStringGrid;
- MainMenu1: TMainMenu;
- File1: TMenuItem;
- Options1: TMenuItem;
- Exit1: TMenuItem;
- Options2: TMenuItem;
- procedure FormCreate(Sender: TObject);
- procedure UpdateInfo(const currentinfo : string);
- private
- fLastCol : integer; {last col written to}
- procedure AdjustColWidth(const whichcol : integer);
- procedure ShowDiff(const tgtcol, tgtrow : integer);
- public
- { Public declarations }
- end;
-
- var
- RunInfoForm: TRunInfoForm;
-
-
- implementation
- uses toolhelp, db;
-
- {$R *.DFM}
- const
- Uheaprow = 1;
- GDIheaprow = 2;
- GlbHeaprow = 3;
- GlbChunkrow = 4;
- {appFootPrintRow = 5;}
- NumDBrow = 5;
- NumTablesRow = 6;
- { Heap info strings }
- UHeapStr = '%d';
- GDIHeapStr = '%d';
- GlbHeapStr = '%10.0n';
- GlbCmpStr = '%10.0n';
- FootPrintStr = '%10.0n';
- SessStr = '%d';
- TblsStr = '%d';
- var
- Info: TSysHeapInfo;
-
- procedure TRunInfoForm.AdjustColWidth(const whichcol : integer);
- var i, x, biggest : integer;
- begin with stringgrid do begin
- biggest := 0;
- for i:= 0 to rowcount -1 do
- if canvas.TextWidth(cells[whichCol,i]) > biggest
- then biggest := canvas.textwidth(cells[WhichCol,i]);
- colWidths[longint(whichCol)] := biggest+6;
- end;
- end;
-
-
- Procedure TRunInfoForm.ShowDiff(const tgtcol, tgtrow : integer);
- var mostRecentCol, prevcol : integer;
-
- function dstrToInt(const s: string): longint;
- var i : integer;
- tmpstr : string;
- const numeric : set of ' '..'z' = ['1', '2', '3', '4', '5', '6', '7', '8', '9','0'];
- begin
- tmpstr := '';
- for i := 1 to length(s) do
- if s[i] in numeric
- then tmpstr := tmpstr + s[i];
- if tmpstr = ''
- then tmpstr := '0';
- result := StrToInt(tmpstr);
- end;
-
- begin
- {first take into account insertion of diff columns}
- if tgtcol = 3
- then begin
- MostRecentcol := 2;
- prevcol := 1;
- end
- else begin
- MostRecentcol := tgtcol - 1;
- prevCol := tgtcol - 3;
- end;
- with stringGrid do
- cells[tgtcol,tgtrow] := intToStr( dstrToInt(cells[PrevCol,tgtrow]) - dstrToInt(cells[MostRecentCol, tgtrow]));
- end;
-
- (**
- function GetWindowInfo(Wnd: HWnd): String;
- var
- Caption: array[0..255] of Char;
- ClassName: array[0..255] of Char;
- ExeName: array[0..255] of Char;
- Instance: Cardinal;
- const
- Visibility: array[False..True] of String[8] = ('(hidden)', '');
- begin
- GetWindowText(Wnd, Caption, SizeOf(Caption));
- GetClassName(Wnd, ClassName, SizeOf(ClassName));
- {$ifndef WIN32}
- Instance := GetWindowWord(Wnd, gww_HInstance);
- {$else}
- Instance := GetWindowLong(Wnd, gwl_HInstance);
- {$endif}
- GetModuleFileName(Instance, ExeName, SizeOf(ExeName));
- Result :=
- '{' + StrPas(ClassName) + '} ' +
- StrPas(ExeName) + ' "' +
- StrPas(Caption) + '" ' +
- Visibility[GetWindowLong(Wnd, gwl_Style) and ws_Visible <> 0];
- end;
-
- function EnumChildWindowsProc(Wnd: HWnd; UserData: Longint): Bool;
- {$ifndef WIN32} export;{$else} stdcall;{$endif}
- begin
- Result := True;
- TOutline(UserData).Lines.Add(#32 + GetWindowInfo(Wnd));
- end;
-
- function EnumWindowsProc(Wnd: HWnd; UserData: Longint): Bool;
- {$ifndef WIN32} export;{$else} stdcall;{$endif}
- begin
- Result := True;
- TOutline(UserData).Lines.Add(GetWindowInfo(Wnd));
- EnumChildWindows(Wnd, @EnumChildWindowsProc, UserData);
- end;
- **)
-
-
- procedure TRunInfoForm.FormCreate(Sender: TObject);
- var
- i,
- biggest : integer;
- bigstr,
- tmpstr : string;
- SearchRec : TSearchRec;
- begin
- visible := false;
- memo1.lines.clear;
- memo1.lines.add('Run information for '+application.exename);
- i := FindFirst(Application.exename, faAnyfile, SearchRec);
- memo1.lines.add(formatDateTime('"Compiled:" dddd, mmmm d, yyyy, ' +
- '"at" hh:mm AM/PM', filedateToDateTime(SearchRec.time)));
- memo1.lines.add('Exe size = '+intToStr(SearchRec.size));
- with stringGrid do begin
- cells[0,0] := ' ';
- cells[0,1] := 'Heap%Free';
- cells[0,2] := 'GDI%Free';
- cells[0,3] := 'FreeBytes';
- cells[0,4] := 'Big Chunk';
- cells[0,5] := 'Num DB:';
- cells[0,6] := 'Num tbls';
-
- { Get initial heap information }
- Info.dwSize := SizeOf(TSysHeapInfo);
- SystemHeapInfo(@Info);
- cells[1,0] := 'Initial';
- cells[01,Uheaprow] :=(Format(UHeapStr, [Info.wUserFreePercent]));
- cells[01,GDiHeaprow] :=(Format(GDIHeapStr, [Info.wGDIFreePercent]));
- cells[01,GlbHeaprow] :=(Format(GlbHeapStr, [1.0*GetFreeSpace(0)]));
- cells[01,GlbChunkrow] :=(format(glbcmpstr, [1.0*GlobalCompact(0)]));
- cells[01,NumDbrow] :=(format(sessStr, [session.databasecount]));
- AdjustColWidth(0);
- AdjustColWidth(1);
- update;
- fLastcol := 1;
- end;
- end;
-
-
- procedure TRunInfoForm.UpdateInfo(const currentinfo : string);
- var
- i, j,
- numtables,
- biggest : integer;
- bigstr,
- tmpstr : string;
- tablelist,
- sessionlist : tstrings;
- begin
- inc(FlastCol);
- with stringGrid do Begin
- colcount := FlastCol + 1;
- Info.dwSize := SizeOf(TSysHeapInfo);
- SystemHeapInfo(@Info);
- cells[FLastCol,0] := currentinfo;
- cells[FLastCol, Uheaprow] :=(Format(UHeapStr, [Info.wUserFreePercent]));
- cells[FLastCol, GDiHeaprow] :=(Format(GDIHeapStr, [Info.wGDIFreePercent]));
- cells[FLastCol, GlbHeaprow] :=(Format(GlbHeapStr, [1.0*GetFreeSpace(0)]));
- cells[FLastCol, GlbChunkrow] :=(format(glbcmpstr, [1.0*GlobalCompact(0)]));
- cells[FLastCol, NumDbrow] :=(format(sessStr, [session.databasecount]));
- with session do begin
- sessionlist := tstringlist.create;
- numtables := 0;
- for i := 0 to databasecount - 1 do
- begin
- sessionlist.add(databases[i].name);
- if databases[i].connected
- then begin
- sessionlist.add(' -> ' + databases[i].databasename);
- tablelist := tstringlist.create;
- session.getTableNames(databases[i].databasename,'*.*', true, true, tablelist);
- numtables := numtables + tablelist.count;
- for j := 0 to tablelist.count -1 do
- tablelist.strings[j] := ' tbl: '+ tablelist.strings[j];
- sessionlist.addStrings(tablelist);
- tablelist.free;
- end;
- end;
- cells[FLastCol, NumTablesRow] := format(tblsStr, [numtables]);
- if rowcount < NumTablesRow + sessionList.count +1
- then rowcount := NumTablesRow + sessionList.count + 1;
- for i := 0 to sessionlist.count -1 do
- cells[FlastCol, NumTablesRow+1+i] := sessionlist.strings[i];
- sessionList.free;
- end; { with session}
- inc(FlastCol);
- colcount := FlastCol + 1;
- cells[FlastCol, 0] := 'used';
- ShowDiff(FLastCol, Uheaprow);
- ShowDiff(FLastCol, GDiHeaprow);
- ShowDiff(FLastCol, GlbHeaprow);
- ShowDiff(FLastCol, GlbChunkrow);
- ShowDiff(FLastCol, NumDbrow);
- ShowDiff(FlastCol, NumTablesRow);
- AdjustColWidth(FLastCol-1);
- AdjustColWidth(FLastCol);
- update;
- end;
- end;
-
- Initialization
-
- RunInfoForm := TrunInfoForm.create(application);
-
- end.
-